//
//  SY_Tch_OrderCell.m
//  ChatDemo-UI2.0
//
//  Created by Sylar on 2016/12/29.
//  Copyright © 2016年 Sylar. All rights reserved.
//

#import "SY_Tch_OrderCell.h"

@implementation SY_Tch_OrderCell
{
    UILabel *titleLabel;
    UILabel *dateLabel;
    UILabel *contentLabel;
    UILabel *fromLabel;
    UILabel *stateLabel;
    UILabel *numLabel;
    
    UIImageView *rightImg;
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 15, SCREENWIDTH - 140, 16)];
        [titleLabel setFont:[UIFont systemFontOfSize:16]];
        [titleLabel setTextColor:colorFromHex(@"#000000")];
        [self.contentView addSubview:titleLabel];
        
        dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREENWIDTH - 132, 16.5, 40, 13)];
        [dateLabel setFont:[UIFont systemFontOfSize:13]];
        dateLabel.textAlignment = NSTextAlignmentRight;
        [dateLabel setTextColor:colorFromHex(@"#979797")];
        [self.contentView addSubview:dateLabel];
        
        contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, titleLabel.bottom+10, titleLabel.width, 15)];
        [contentLabel setFont:[UIFont systemFontOfSize:15]];
        [contentLabel setTextColor:colorFromHex(@"#979797")];
        [self.contentView addSubview:contentLabel];
        
        UILabel *defautlabel = [[UILabel alloc]initWithFrame:CGRectMake(15, contentLabel.bottom +11 , 30, 12)];
        [defautlabel setFont:[UIFont systemFontOfSize:12]];
        [defautlabel setTextColor:colorFromHex(@"#3b3b3b")];
        [defautlabel setText:@"来源:"];
        [self.contentView addSubview:defautlabel];
        
        
        fromLabel = [[UILabel alloc]initWithFrame:CGRectMake(defautlabel.right, defautlabel.y, 65, 12)];
        [fromLabel setFont:[UIFont systemFontOfSize:12]];
        [fromLabel setTextColor:colorFromHex(@"#3b3b3b")];
        if (SCREENWIDTH > 320) {
            fromLabel.width = 80;
        }
        [self.contentView addSubview:fromLabel];
        
        UILabel *defautlabel1 = [[UILabel alloc]initWithFrame:CGRectMake(fromLabel.right, defautlabel.y, 60, 12)];
        [defautlabel1 setFont:[UIFont systemFontOfSize:12]];
        [defautlabel1 setTextColor:colorFromHex(@"#3b3b3b")];
        [defautlabel1 setText:@"已/未收费:"];
        [self.contentView addSubview:defautlabel1];
        
        numLabel = [[UILabel alloc]initWithFrame:CGRectMake(defautlabel1.right, defautlabel1.y, 30, 12)];
        [numLabel setFont:[UIFont systemFontOfSize:12]];
        //[numLabel setTextColor:colorFromHex(@"#3b3b3b")];
        numLabel.textAlignment = NSTextAlignmentLeft;
        [self.contentView addSubview:numLabel];
        
        rightImg = [[UIImageView alloc]initWithFrame:CGRectMake(SCREENWIDTH - 79, 16, 64, 64)];
        
        [self.contentView addSubview:rightImg];
        
        stateLabel = [[UILabel alloc]initWithFrame:CGRectMake(numLabel.right+2, defautlabel.y, 40, 12)];
        if (SCREENWIDTH > 320) {
            stateLabel.x = numLabel.right;
        }
        [stateLabel setFont:[UIFont systemFontOfSize:12]];
        [stateLabel setTextColor:colorFromHex(@"#979797")];
        stateLabel.hidden = YES;
        stateLabel.text = @"已结束";
        stateLabel.autoresizingMask =  UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
        [self.contentView addSubview:stateLabel];
        
        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 95.5, SCREENWIDTH, 0.5)];
        [lineView setBackgroundColor:colorFromHex(@"#DEDEDE")];
        [self.contentView addSubview:lineView];
        
    }
    
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)creatCell:(SY_Par_PaymentModel *)model {
    
    titleLabel.text = model.name;
    contentLabel.text = model.scontent;
    fromLabel.text = model.classname;
    NSString * picURL = [NSString stringWithFormat:@"%@%@",IMAGEHOSTURL,model.toppic];
    [rightImg sd_setImageWithURL:[NSURL URLWithString:picURL] placeholderImage:[UIImage imageNamed:@"noImage"]];
    
    NSString *dateStr = [model.jointime substringWithRange:NSMakeRange(5,5)];
    dateLabel.text = dateStr;
    
    NSString *noPaystr = [NSString stringWithFormat:@"%ld",(model.znum - model.paynum)];
    
    NSString *numStr = [NSString stringWithFormat:@"%ld/%@",model.paynum,noPaystr];
    
    NSMutableAttributedString *numAttstr = [[NSMutableAttributedString alloc]initWithString:numStr];

    
    [numAttstr addAttribute:NSForegroundColorAttributeName
                      value:colorFromHex(@"#39adff")
                      range:NSMakeRange(numStr.length - noPaystr.length, noPaystr.length)];
    
    numLabel.attributedText = numAttstr;
    
    
    stateLabel.hidden = model.state == 2?NO:YES;
    
    if (model.state == 9) {
        stateLabel.hidden = NO;
        stateLabel.text = @"未开始";
    }else if (model.state == 2) {
        stateLabel.text = @"已结束";
    }
    
    
}

@end
